<script>
export default {
  name: 'MyList',
  data() {
    return {
      info:{
        isFirst: true,
        list: [],
        isLoading: false,
        errorMsg: ""
      }
    }
  },
  mounted() {
    // this.$bus.$on("updateListData", (dataObj) => {
    //   this.isFirst = dataObj.isFirst;
    //   this.isLoading = dataObj.isLoading;
    //   this.errorMsg = dataObj.errorMsg;
    //   this.list = dataObj.userList;
    // })

    //es6解构赋值
    this.$bus.$on("updateListData", (dataObj) => {
      this.info = { ...this.info, ...dataObj };
    })
  }
}
</script>

<template>
  <div class="row">
    <div class="card"
         v-show="list.length"
         v-for="user in info.list"
         :key="user.id"
    >
      <a :href="user.html_url" target="_blank">
        <img :src="user.avatar_url" style="width: 100px">
      </a>
      <p class="card-text">{{user.login}}</p>
    </div>
    <h1 v-show="info.isFirst">欢迎使用</h1>
    <h1 v-show="info.isLoading">页面加载中...</h1>
    <h1 v-show="info.errorMsg">页面出错了,错误信息:{{errorMsg}}</h1>
  </div>
</template>

<style scoped>
.album {
  min-height: 50rem;
  background-color: #f7f7f7;
  padding-top: 3rem;
  padding-bottom: 3rem;
}

.card {
  float: left;
  width: 33.33%;
  padding: .75rem;
  margin-bottom: 2rem;
  border: 1px solid #efefef;
  text-align: center;
}

.card > img {
  margin-bottom: .75rem;
  border-radius: 100px;
}

.card-text {
  font-size: 85%;
}
</style>